package com.t01.bdqn.design.proxy.dynamic;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class StudentJDKProxy implements InvocationHandler {

    /**
     * 被代理的目标对象
     */
    private Object target;
    public void setTarget(Object target) {
        this.target = target;
    }
    /**
     * 为被代理的接口方法定义的代理业务规则
     */
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        before();
        //被代理类的方法正常执行
        Object result = method.invoke(target,args);
        after();
        return result;
    }

    public void before() {
        System.out.println("方法前处理");
    }

    public void after() {
        System.out.println("方法后处理");
    }

}
